package ru.algorithm.clusterization.cftree2;

/**
 * Yuri Zemlyanskiy <urikz@yandex-team.ru>
 * Date: 05.05.2011
 */
public abstract class AbstractCFNode {

    abstract public int getPointNumber();

    abstract public double[] getSum();

    abstract public double[] getSum2();

    protected double distance(final AbstractCFNode node) {
        return d0(this, node);
    }

    private double d0(AbstractCFNode node1, AbstractCFNode node2) {
        double distance = 0;
        int dimention = node1.getSum().length;
        double[] s1 = node1.getSum();
        double[] s2 = node2.getSum();

        for(int i=0; i < dimention; i++) {
            double diff = s1[i] / dimention - s2[i] / dimention;
            distance += diff*diff;
        }
        return Math.sqrt(distance);
    }

}
